<?php
require(dirname(__FILE__) . '/includes/init.php');
if(!empty($_REQUEST['adid'])){
	/*$sn_list = $db->getAll("select count(s.stats_id) as num,s.referer_path from ".$ecs->table('stats')."as s where ad_id='".$_REQUEST['adid']."' group by referer_path");
	$total_num = 0;
	$total_visit = 0;
	foreach($sn_list as $i=>$sn){
		$visits = $db->getRow("select count(pv.visit_id) as visit,products_name from ".$ecs->table('page_visit')."as pv inner join ".$ecs->table('page')."as p on pv.products_sn=p.products_sn where pv.products_sn='".$sn['referer_path']."'");
		$sn_list[$i]['visit'] = $visits['visit'];
		$sn_list[$i]['products_name'] = $visits['products_name'];
		$total_num += $sn['num'];
		$total_visit += $visits['visit'];
	}*/
	$page_ids = $db->getOne("select page_ids from ".$ecs->table('pic_ad')." where ad_id='".$_REQUEST['adid']."'");
	$sn_list = array();
	$total_num = 0;
	$total_visit = 0;
	if($page_ids){
		$ids = explode(',',$page_ids);
		for($i=0;$i<sizeof($ids);$i++){
			$result = $db->getRow("select count(pv.visit_id) as visit,p.products_name from ".$ecs->table('page_visit')." as pv inner join ".$ecs->table('page')." as p on pv.products_sn=p.products_sn where pv.products_sn='".$ids[$i]."'");
			
			$click = $db->getOne("select count(stats_id) as click from ".$ecs->table('stats')." where ad_id='".$_REQUEST['adid']."' and referer_path='".$ids[$i]."'");
			$sn_list[$i]['products_name'] = $result['products_name'];
			$sn_list[$i]['visit'] = $result['visit'];
			$sn_list[$i]['num'] = $click;
			$total_num += $click;
			$total_visit += $result['visit'];
		}
	}
	
}else{
	header("Location: ads.php");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>管理中心 - 广告统计 </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/general.css" rel="stylesheet" type="text/css" />
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
 
<h1>
<span class="action-span"><a href="ads.php">广告列表</a></span>
<span class="action-span1"><a target="_top" href="index.php?act=main">管理中心</a> </span><span id="search_id" class="action-span1"> - 广告列表 </span>
<div style="clear:both"></div>
</h1>
<div class="list-div" id="listDiv"> 
<table cellpadding="3" cellspacing="1">
  <tr>
    <th>来源名</th>
    <th>点击数</th>
    <th>访问数</th>
  <tr>
  <?php 
	if(count($sn_list)>0){
		foreach($sn_list as $sn){
  ?>
   <tr>
    <td><?php echo $sn['products_name']?></td>
    <td><?php echo $sn['num'];?></td>
    <td><?php echo $sn['visit'];?></td>
  <tr>
  <?php 
		}
    }
  ?>
  <tr>
    <td>总计：</td>
    <td><?php echo $total_num;?></td>
    <td><?php echo $total_visit;?></td>
  <tr>
  </table>
<!-- 分页 -->
  </div>
</body>
</html>